package com.zhongyewx.teachercert.framework.skin;

import android.content.Context;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class ZYSkinFactory {

    private List<SkinItem> skinItems = new ArrayList<>();
    public static String ATTR_NAME_BG = "background";
    public static String ATTR_NAME_TEXT = "text";
    public static String ATTR_TYPE_COLOR = "color";
    public static String ATTR_TYPE_SIZE = "size";


    public void collectViewAttr(View view, Context context, String attrName, String attrType, int resId) {
        List<SkinAttr> skinAttrs = new ArrayList<>();
        skinAttrs.add(new SkinAttr(attrName,attrType,"",resId));
        for (SkinItem item: skinItems){
            if (item.getView().getId() == view.getId()){
                item.setAttrs(skinAttrs);
                item.apply(context);
                return;
            }
        }
        SkinItem skinItem = new SkinItem(view, skinAttrs);
        skinItem.apply(context);
        skinItems.add(skinItem);
    }

    public void collectViewAttr(View view,Context context, String attributeName, int resId, String attrType, String resName) {
        List<SkinAttr> skinAttrs = new ArrayList<>();
        skinAttrs.add(new SkinAttr(attributeName,attrType,resName,resId));
        SkinItem skinItem = new SkinItem(view, skinAttrs);
//                    if (SkinManager.getInstance().isExternalSkin()){
            skinItem.apply(context);
//                    }
        skinItems.add(skinItem);
    }

    private boolean isSupportedAttr(String attributeName){
        return "background".equals(attributeName) || "textColor".equals(attributeName);
    }

    public void apply(Context context){
        for (SkinItem item : skinItems) {
            item.apply(context);
        }
    }

}
